let g:vimfiles = get(g:, 'vimfiles', fnamemodify(expand('<sfile>:p'), ':p:h:h:h'))
let g:plug_root = get(g:, 'plug_root', fnamemodify(substitute(g:vimfiles, '\', '/', 'g') . '/pack/github.com/opt/', ':p'))
let g:plug_root_gitee = get(g:, 'plug_root_gitee', fnamemodify(substitute(g:vimfiles, '\', '/', 'g') . '/pack/gitee.com/opt/', ':p'))

function! plugin#vim_plug#load() abort
    if !exists('g:loaded_plug')
        packadd vim-plug
        runtime! plug.vim
    endif
    return exists('g:loaded_plug')
endfunction

function! plugin#vim_plug#github_old() abort
    call plug#begin(g:plug_root)
    " Make sure you use single quotes
    Plug 'junegunn/vim-plug'
    Plug 'leafOfTree/vim-project'
    Plug 'jreybert/vimagit'
    Plug 'ctrlpvim/ctrlp.vim'
    " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
    Plug 'junegunn/vim-easy-align'
    " Any valid git URL is allowed
    " Plug 'https://github.com/junegunn/vim-github-dashboard.git'
    " Multiple Plug commands can be written in a single line using | separators
    Plug 'SirVer/ultisnips'
    " Plug 'https://gitee.com/BIT_chenxinliang/UltiSnips'
    " Plug 'honza/vim-snippets'
    Plug 'keelii/vim-snippets'
    " On-demand loading
    " Plug 'preservim/nerdtree', { 'on': 'NERDTreeToggle' }
    " Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
    " Using a non-default branch
    " Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
    " Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
    " Plug 'fatih/vim-go', { 'tag': '*' }
    " Plugin options
    " Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
    " Plugin outside ~/.vim/plugged with post-update hook
    " Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | Plug 'junegunn/fzf.vim'
    Plug 'junegunn/fzf', { 'do': './install --all' } | Plug 'junegunn/fzf.vim'
    " Unmanaged plugin (manually installed and updated)
    " Plug '~/my-prototype-plugin'
    "
    Plug 'Yggdroot/LeaderF'
    " Plug 'https://gitee.com/BIT_chenxinliang/LeaderF'
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    Plug 'easymotion/vim-easymotion'
    Plug 'prabirshrestha/vim-lsp'
    Plug 'mattn/vim-lsp-settings'
    Plug 'liuchengxu/vim-which-key'
    Plug 'vimwiki/vimwiki'
    Plug 'vim-voom/VOoM'
    Plug 'vim-pandoc/vim-pandoc'
    " Plug 'https://gitee.com/BIT_chenxinliang/vim-pandoc'
    Plug 'vim-pandoc/vim-pandoc-syntax'
    " Plug 'https://gitee.com/BIT_chenxinliang/vim-pandoc-syntax'
    Plug 'vim-scripts/AutoComplPop'
    " Plug 'https://gitee.com/BIT_chenxinliang/AutoComplPop'
    Plug 'iamcco/markdown-preview.nvim'
    Plug 'timofurrer/pandoc-plantuml-filter'
    Plug 'kdheepak/lazygit.nvim'
    Plug 'hotoo/pangu.vim'
    Plug 'skywind3000/vim-terminal-help'
    Plug 'skywind3000/vim-quickui'
    " Plug 'https://gitee.com/BIT_chenxinliang/vim-quickui'
    Plug 'tibabit/vim-templates'
    " Plug 's1341/vim-tabws'
    Plug 'dense-analysis/ale'
    " Plug 'https://gitee.com/BIT_chenxinliang/ale'
    Plug 'dbakker/vim-projectroot'
    Plug 'MattesGroeger/vim-bookmarks'
    " Plug 'https://gitee.com/BIT_chenxinliang/vim-bookmarks'
    Plug 'Shougo/vimproc'
    " Plug 'https://gitee.com/BIT_chenxinliang/vimproc'
    Plug 'Shougo/defx.nvim'
    " Plug 'https://gitee.com/BIT_chenxinliang/defx.nvim'
    Plug 'Shougo/unite.vim'
    Plug 'Shougo/vimfiler.vim'
    Plug 'Shougo/neosnippet.vim'
    Plug 'Shougo/neosnippet-snippets'
    Plug 'skywind3000/asyncrun.vim'
    Plug 'skywind3000/asynctasks.vim'
    Plug 'jlanzarotta/bufexplorer'
    " Plug 'https://gitee.com/BIT_chenxinliang/bufexplorer'
    Plug 'bling/vim-bufferline'
    " Plug 'https://gitee.com/BIT_chenxinliang/vim-bufferline'
    " Plug 'cdelledonne/vim-cmake'
    Plug 'vhdirk/vim-cmake'
    " Plug 'commentary'
    " Plug 'context_filetype'
    " Plug 'denite'
    " Plug 'dict'
    " Plug 'fullscreen'
    " Plug 'imselect'
    " Plug 'julia'
    " Plug 'leaderGuide'
    " Plug 'lspconfig'
    " Plug 'showmarks'
    " Plug 'slime'
    Plug 'jpalardy/vim-slime'
    " Plug 'tabline'
    " Plug 'tabnine'
    " Plug 'vimtex'
    " " Plug 'ycm'
    " Plug '/NrrwRgn'
    " Plug '/battery.vim'
    " Plug 'coc.nvim'
    " Plug '/coc-explorer'
    " Plug '/coc-lists'
    " Plug '/coc-pyright'
    " Plug '/coc-snippets'
    " Plug '/defx.nvim'
    " Plug '/fzf'
    " Plug '/gruvbox'
    " Plug 'xqin/gvimfullscreen'
    Plug 'https://gitee.com/BIT_chenxinliang/gvimfullscreen.git'
    " Plug '/jedi-vim'
    " Plug '/neomake'
    " Plug '/neomru.vim'
    " Plug '/neoyank.vim'
    " Plug '/notes'
    " Plug '/nvim-yarp'
    " Plug '/powerline-fonts'
    " Plug '/promptline.vim'
    " Plug '/tagbar'
    " Plug '/undotree'
    " Plug '/unicode.vim'
    " Plug '/unite-bibtex'
    " Plug '/unite-git-log'
    " Plug '/unite-gtags'
    " Plug '/unite-help'
    " Plug '/unite-quickfix'
    " Plug '/unite-tag'
    " Plug '/vim-better-sml'
    " Plug '/vim-bookmark'
    " Plug '/vim-bookmarks'
    " Plug '/vim-bufferline'
    " Plug '/vim-clap'
    " Plug '/vim-colors-solarized'
    Plug 'vim-ctrlspace/vim-ctrlspace'
    " Plug '/vim-cursormode'
    " Plug '/vim-dirvish'
    " Plug '/vim-easygit'
    " Plug '/vim-galore-zh_cn'
    " Plug '/vim-gitgutter'
    " Plug '/vim-gutentags'
    " Plug '/vim-hug-neovim-rpc'
    " Plug '/vim-leader-guide'
    " Plug '/vim-localsearch'
    " Plug '/vim-lsp-cxx-highlight'
    " Plug '/vim-markdown-preview'
    " Plug '/vim-markdown'
    " Plug '/vim-matlab-fold'
    " Plug '/vim-matlab'
    " Plug '/vim-orgmode'
    " Plug '/vim-pandoc-syntax'
    " Plug '/vim-pandoc'
    " Plug '/vim-repl'
    " Plug '/vim-sensible'
    " Plug '/vim-sml'
    " Plug '/vim-startify'
    " Plug '/vim-surround'
    " Plug '/vim-table-mode'
    Plug 'kana/vim-textobj-entire'
    Plug 'kana/vim-textobj-function'
    Plug 'kana/vim-textobj-indent'
    Plug 'sgur/vim-textobj-parameter'
    Plug 'kana/vim-textobj-syntax'
    Plug 'kana/vim-textobj-user'
    " Plug '/vim-translate'
    Plug 'tpope/vim-unimpaired'
    Plug 'thinca/vim-unite-history'
    Plug 'yianwillis/vimcdoc'
    Plug 'troydm/zoomwintab.vim'
    " Plug 'github/copilot.vim'
    call plug#end()
endfunction

function! plugin#vim_plug#init() abort
	try
        if plugin#vim_plug#load()
            call plugin#vim_plug#gitee()
            call plugin#vim_plug#github()
            " PlugInstall
        endif
    catch
        echom v:exception
    endtry
endfunction

function! plugin#vim_plug#github() abort
    call plug#begin(g:plug_root)
    Plug 'junegunn/vim-plug'
    Plug 'leafOfTree/vim-project'
    Plug 'jreybert/vimagit'
    Plug 'ctrlpvim/ctrlp.vim'
    Plug 'junegunn/vim-easy-align'
    Plug 'SirVer/ultisnips'
    Plug 'keelii/vim-snippets'
    Plug 'preservim/nerdtree', { 'on': 'NERDTreeToggle' }
    Plug 'junegunn/fzf', { 'do': './install --all' } 
    Plug 'junegunn/fzf.vim'
    Plug 'Yggdroot/LeaderF'
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    Plug 'easymotion/vim-easymotion'
    Plug 'prabirshrestha/vim-lsp'
    Plug 'mattn/vim-lsp-settings'
    Plug 'liuchengxu/vim-which-key'
    Plug 'vimwiki/vimwiki'
    Plug 'vim-voom/VOoM'
    Plug 'vim-pandoc/vim-pandoc'
    Plug 'vim-pandoc/vim-pandoc-syntax'
    Plug 'vim-scripts/AutoComplPop'
    Plug 'iamcco/markdown-preview.nvim'
    Plug 'timofurrer/pandoc-plantuml-filter'
    Plug 'kdheepak/lazygit.nvim'
    Plug 'hotoo/pangu.vim'
    Plug 'skywind3000/vim-terminal-help'
    Plug 'skywind3000/vim-quickui'
    Plug 'tibabit/vim-templates'
    Plug 'dense-analysis/ale'
    Plug 'dbakker/vim-projectroot'
    Plug 'MattesGroeger/vim-bookmarks'
    Plug 'Shougo/vimproc'
    Plug 'Shougo/defx.nvim'
    Plug 'Shougo/unite.vim'
    Plug 'Shougo/vimfiler.vim'
    Plug 'Shougo/neosnippet.vim'
    Plug 'Shougo/neosnippet-snippets'
    Plug 'skywind3000/asyncrun.vim'
    Plug 'skywind3000/asynctasks.vim'
    Plug 'jlanzarotta/bufexplorer'
    Plug 'bling/vim-bufferline'
    Plug 'vhdirk/vim-cmake'
    Plug 'jpalardy/vim-slime'
    Plug 'vim-ctrlspace/vim-ctrlspace'
    Plug 'kana/vim-textobj-entire'
    Plug 'kana/vim-textobj-function'
    Plug 'kana/vim-textobj-indent'
    Plug 'sgur/vim-textobj-parameter'
    Plug 'kana/vim-textobj-syntax'
    Plug 'kana/vim-textobj-user'
    Plug 'tpope/vim-unimpaired'
    Plug 'thinca/vim-unite-history'
    Plug 'yianwillis/vimcdoc'
    Plug 'troydm/zoomwintab.vim'
    Plug 'github/copilot.vim'
    call plug#end()
endfunction

function! plugin#vim_plug#gitee() abort
    call plug#begin(g:plug_root_gitee)
    Plug 'https://gitee.com/wmeng223/copilot.vim.git'
    Plug 'https://gitee.com/BIT_chenxinliang/vim-pandoc'
    Plug 'https://gitee.com/BIT_chenxinliang/vim-pandoc-syntax'
    Plug 'https://gitee.com/BIT_chenxinliang/AutoComplPop'
    Plug 'https://gitee.com/BIT_chenxinliang/gvimfullscreen.git'
    Plug 'https://gitee.com/BIT_chenxinliang/bufexplorer'
    Plug 'https://gitee.com/BIT_chenxinliang/vimtex.git'
    call plug#end()
endfunction
